<template>
  <div class="content">
    <div class="login-wrapper">
      <div class="left-img">
        <div class="glass">
          <div class="tips">
            <div class="title">
              THE HNIST NETWORK
            </div>
            <h1>Explore The Universe</h1>
            <span>5 Million+ people have joined our network.</span>
            <span>we invite you to join the tribe.</span>
          </div>
        </div>
      </div>
      <div class="right-login-form">
        <div class="form-wrapper">
          <h1>Log in</h1>
          <div v-show="!isEmailLogin">
            <div class="input-items">
                        <span class="input-tips">
                            Account Number
                            <span class="login-mode" @click="changeLoginMode">email login</span>
                        </span>
              <input v-model="loginForm.username" autocomplete="off" class="inputs"
                     placeholder="Enter your account" type="text">
            </div>
            <div class="input-items">
                        <span class="input-tips">
                            Password
                        </span>
              <input v-model="loginForm.password" autocomplete="off" class="inputs" placeholder="Enter your password"
                     type="password">
            </div>
            <button class="btn" @click="handleAccountLogin">Log in</button>
          </div>
          <div v-show="isEmailLogin">
            <div class="input-items">
                        <span class="input-tips">
                            Email Address
                            <span class="login-mode" @click="changeLoginMode">account login</span>
                        </span>
              <input v-model="loginForm.email" autocomplete="off" class="inputs" placeholder="Enter your email"
                     type="text">
            </div>
            <div class="input-items">
                        <span class="input-tips">
                            Email Code
                        </span>
              <input v-model="loginForm.code" autocomplete="off" class="email-inputs"
                     placeholder="verification code">
              <button class="send-code" @click.prevent="getEmailCode">send code</button>
            </div>
            <button class="btn" @click.prevent="handleEmailLogin">Log in</button>
          </div>
          <div class="signup-tips">
            <span>Don't Have An Account?</span>
            <span class="login-mode" @click="">Sign up</span>
          </div>
          <div class="other-login">
            <div class="divider">
              <span class="line"></span>
              <span class="divider-test">or</span>
              <span class="line"></span>
            </div>
            <div class="other-login-wrapper">
              <div class="other-login-item">
                <a href="http://localhost:8160/wx/login">
                  <img alt="微信"
                       src="https://yao-yu-blog-1314163000.cos.ap-guangzhou.myqcloud.com/database/mysql202304270835472.png">
                </a>
              </div>
              <div class="other-login-item">
                <a href="http://localhost:8160/wx/login">
                  <img alt="QQ"
                       src="https://yao-yu-blog-1314163000.cos.ap-guangzhou.myqcloud.com/database/mysql202304270835471.png">
                </a>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import useUserStore from '@/store/modules/user'
import {useRoute, useRouter} from "vue-router";

const userStore = useUserStore()
const route = useRoute();
const router = useRouter();
const {proxy} = getCurrentInstance();

const loginForm = ref({
  username: "",
  password: "",
  email: "",
  code: "",
  uuid: ""
});
// 验证码开关
const captchaEnabled = ref(true);
let isEmailLogin = ref(false);

function handleAccountLogin() {
  userStore.login(loginForm.value).then(() => {
    proxy.$message({
      message: "登录成功",
      type: "success"
    });
    router.push({path: "/"});
  })
}

function handleEmailLogin() {
  userStore.emailLogin(loginForm.value).then(() => {
    proxy.$message({
      message: "登录成功",
      type: "success"
    });
    router.push({path: "/"});
  })
}

function getEmailCode() {
  userStore.sendEmailCode(loginForm.value.email).then(res => {
    captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled;
    if (captchaEnabled.value) {
      loginForm.value.uuid = res.uuid;
    }
    //提示邮箱发送成功
    proxy.$message({
      message: "验证码发送成功",
      type: "success"
    });
  });
}

function changeLoginMode() {
  isEmailLogin.value = !isEmailLogin.value;
}
</script>

<style scoped>
* {
  padding: 0;
  margin: 0;
  font-family: "Aguazyuan", Courier, monospace;
}

.content {
  width: 100vw;
  height: 100vh;
  background-color: rgba(79, 137, 243, 0.21);
  position: relative;
  -webkit-user-select: none;
  -moz-user-select: none;
  -o-user-select: none;
  user-select: none;
}

.content .login-wrapper {
  width: 70vw;
  height: 80vh;
  background-color: #fff;
  border-radius: 40px;
  position: relative;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  overflow: hidden;
}

.content .login-wrapper .left-img {
  border-radius: 40px;
  flex: 1;
  background: url("https://yao-yu-blog-pic-1314163000.cos.ap-guangzhou.myqcloud.com/Snipaste_2024-04-09_14-47-09.png") no-repeat;
  background-size: cover;
  position: relative;
}

.content .login-wrapper .left-img .glass {
  width: 60%;
  padding: 20px;
  color: #fff;
  position: absolute;
  top: 20%;
  left: 50%;
  transform: translate(-50%, -20%);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 32px 0 rgba(50, 33, 41);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 15px;
  border: 1px solid rgba(255, 255, 255, 0.48);
}

.content .login-wrapper .left-img .tips .title {
  width: 25%;
  font-weight: 600;
  font-size: 15px;
  text-align: center;
  padding: 10px;
  margin: 10px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 32px 0 rgb(227, 227, 235);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-radius: 15px;
  border: 1px solid #fff;
}

.content .login-wrapper .left-img .tips h1 {
  margin: 15px;
}

.content .login-wrapper .left-img .tips span {
  margin: 5px 0;
  display: block;
  font-weight: 100;
}

.content .login-wrapper .right-login-form {
  flex: 1;
  position: relative;

}

.content .login-wrapper .right-login-form .form-wrapper {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 60%;
  transform: translate(-50%, -50%);
}

.content .login-wrapper .right-login-form .form-wrapper h1 {
  font-size: 30px;
  text-align: center;
}

.content .login-wrapper .right-login-form .form-wrapper .input-items {
  margin: 20px 0;
}

.content .login-wrapper .right-login-form .form-wrapper .input-items .input-tips {
  display: block;
  font-weight: 600;
  font-size: 20px;
  margin: 5px 0;
}
.content .login-wrapper .right-login-form .form-wrapper .input-items .input-tips .login-mode {
  position: relative;
  font-weight: 600;
  font-size: 15px;
  margin: 5px 0;
  float: right;
  right: 30px;
  color: rgba(50, 33, 41, 0.5);
  cursor: pointer;
}

.content .login-wrapper .right-login-form .form-wrapper .input-items .input-tips .login-mode:active {
  color: rgba(50, 33, 41);
}

.content .login-wrapper .right-login-form .form-wrapper .input-items .inputs {
  width: 100%;
  height: 50px;
  box-sizing: border-box;
  border: 2px solid rgba(150, 147, 147, 0.7411764706);
  border-radius: 15px;
  font-size: 17px;
  padding-left: 20px;
  outline: none;
  transition: 0.5s;
}

.content .login-wrapper .right-login-form .form-wrapper .input-items .inputs:focus {
  border: 2px solid #0f2931;
}

.content .login-wrapper .right-login-form .form-wrapper .input-items .email-inputs {
  width: 60%;
  height: 50px;
  box-sizing: border-box;
  border: 2px solid rgba(150, 147, 147, 0.7411764706);
  border-radius: 15px;
  font-size: 17px;
  padding-left: 20px;
  outline: none;
  transition: 0.5s;
}

.content .login-wrapper .right-login-form .form-wrapper .input-items .email-inputs:focus {
  border: 2px solid rgba(50, 33, 41);
}

.send-code {
  width: 35%;
  position: relative;
  left: 5%;
  height: 50px;
  border-radius: 15px;
  font-size: 15px;
  background-color: rgba(50, 33, 41);
  color: #fff;
  border: 0;
  transition: 0.3s;
  margin: 0 0;
  cursor: pointer;
}

.send-code:active {
  transform: scale(0.96);
}

.content .login-wrapper .right-login-form .form-wrapper .btn {
  width: 100%;
  height: 50px;
  border-radius: 15px;
  font-size: 25px;
  background-color: rgba(50, 33, 41);
  color: #fff;
  border: 0;
  transition: 0.5s;
  margin: 20px 0;
  cursor: pointer;
}

.content .login-wrapper .right-login-form .form-wrapper .btn:active {
  transform: scale(0.96);
}

.content .login-wrapper .right-login-form .form-wrapper .signup-tips {
  font-weight: 600;
}

.content .login-wrapper .right-login-form .form-wrapper .signup-tips span:last-child {
  float: right;
  color: rgba(50, 33, 41, 0.5);
  cursor: pointer;
}

.content .login-wrapper .right-login-form .form-wrapper .signup-tips span:last-child:active {
  color: rgba(50, 33, 41);
}

.content .login-wrapper .right-login-form .form-wrapper .other-login {
  width: 100%;
}

.content .login-wrapper .right-login-form .form-wrapper .other-login .divider {
  width: 100%;
  margin: 20px 0;
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.content .login-wrapper .right-login-form .form-wrapper .other-login .divider .line {
  display: inline-block;
  max-width: 35%;
  width: 35%;
  flex: 1;
  height: 1px;
  background-color: rgb(162, 172, 185);
}

.content .login-wrapper .right-login-form .form-wrapper .other-login .divider .divider-test {
  vertical-align: middle;
  margin: 0 20px;
  display: inline-block;
  width: 50px;
  color: rgb(162, 172, 185);
  white-space: normal;
}

.content .login-wrapper .right-login-form .form-wrapper .other-login .other-login-wrapper {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.content .login-wrapper .right-login-form .form-wrapper .other-login .other-login-wrapper .other-login-item {
  width: 70px;
  height: 70px;
  margin: 0 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  cursor: pointer;
  transition: 0.3s;
}

.content .login-wrapper .right-login-form .form-wrapper .other-login .other-login-wrapper .other-login-item img {
  width: 40px;
  height: 40px;
}

.content .login-wrapper .right-login-form .form-wrapper .other-login .other-login-wrapper .other-login-item:active {
  background-color: rgba(186, 100, 236, 0.171);
  transform: scale(0.96);
}
@media (max-width: 1024px) {
  .login-wrapper {
    padding: 20px;
  }

  .login-wrapper .left-img {
    display: none;
  }

  .login-wrapper .right-login-form {
    padding: 20px;
  }
}
</style>
